package br.com.chat.controller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;


public class ClienteView {
	JTextArea entrada;
	JTextField saida;
	ClienteChat chat;
	PrintWriter writer;
	public ClienteView(PrintWriter writer) {
		this.writer = writer;
	}

	public void montaJanela(){
		JFrame frame = new JFrame("MEU PRIMEIRO CHAT");
		JPanel painelPrincipal = new JPanel();
		entrada = new JTextArea("Texto 123", 15, 50);
		entrada.setLineWrap(true);
		entrada.setWrapStyleWord(true);
		entrada.setEditable(false);
		JScrollPane qScroller = new JScrollPane(entrada);
		qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		saida = new JTextField(20);
		JButton enviaDados = new JButton("Enviar");
		enviaDados.addActionListener(new SendButtonListener());
		painelPrincipal.add(qScroller);
		painelPrincipal.add(saida);
		painelPrincipal.add(enviaDados);
		frame.add(painelPrincipal);
		frame.setSize(500,500);
		frame.setVisible(true);
	}
	
	public class SendButtonListener implements ActionListener {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			writer.println(saida.getText());
			writer.flush();
			saida.setText("");
			saida.requestFocus();
		}
	}
}
